using Common.Commands;
using Common.Commands.FolderCommands;
using Core.Domain.Model;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.FolderProcessors
{
	public class UpdateFolderProcessor : ICommandProcessor<UpdateFolder>
	{
		private readonly IRepository<Folder> _repository;

		public UpdateFolderProcessor(IRepository<Folder> repository)
		{
			_repository = repository;
		}

		public dynamic Process(UpdateFolder command)
 		{
			var response = new WebApiResultResponse();

			var folder = _repository.GetById(command.Id);
            
			folder.Tags = command.Tags;
		    folder.Name = command.Name;
		    folder.Description = command.Description;
		    folder.ReferenceId = command.ReferenceId;
		    folder.ReferenceName = command.ReferenceName;
		    folder.EntityType = command.EntityType;
		    folder.ImageData = command.ImageData;
		    folder.ModifiedBy = command.UserId;

			_repository.Update(folder);

			response.IsSuccess = true;

			return response;
		}
	}
}
